package doc.webapp;

import javax.swing.plaf.TableHeaderUI;

import org.pegdown.*;
import org.pegdown.ast.*;

public class PegdownUtils {

    public static String asHtml(String source) {
        PegDownProcessor p = new PegDownProcessor(Extensions.ALL - Extensions.SMARTYPANTS);
        RootNode root = p.parseMarkdown(source.toCharArray());
        return new HighlightHtmlSerializer().toHtml(root);
    }

    static class HighlightHtmlSerializer extends ToHtmlSerializer {
        static final LinkRenderer INSTANCE = new LinkRenderer();

        public HighlightHtmlSerializer() {
            super(INSTANCE);
        }

        @Override
        public void visit(VerbatimNode node) {
            printer.println();
           /* printer.print("<script type=\"syntaxhighlighter\" class=\"brush: ");
            String lang = node.getType();
            printer.print((lang == null || lang.length() == 0) ? "text" : lang);
            printer.print("\"><![CDATA[\n").print(node.getText()).print("]]></script>");*/
            String nodeText = node.getText();
            nodeText = nodeText.replace("<", "&lt;");
            nodeText = nodeText.replace(">", "&gt;");
            printer.print("<div class=\"highlight\"><pre><code class=\"language-html\">").print(nodeText).print("</code></pre></div>");
        }
        
        
    }
}
